<div style="margin: 15px;">
	<div class="layui-row">
		<div class="layui-col-md10">
			<form class="layui-form">
				<input type="hidden" name="templateCourseId" id="templateCourseId" value="">
				<div class="layui-form-item">
					<label class="layui-form-label">标题</label>
					<div class="layui-input-inline">
						<input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">分类</label>
					<!--<div class="layui-input-inline">-->
					<!--<input type="text" name="loginName" placeholder="请输入" autocomplete="off" class="layui-input">-->
					<!--</div>-->
					<div class="layui-input-inline">
						<!--<input type="hidden" id="menu" name="classify" placeholder="请选择" autocomplete="off" class="layui-input">-->
						<select name="classify" lay-filter="fenlei" id="dict" lay-verify="required">
							<option value="">--请选择--</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">课时</label>
					<div class="layui-input-inline">
						<input type="number" name="classtime" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">学分</label>
					<div class="layui-input-inline">
						<input type="number" name="score" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux"> </div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">简介</label>
					<div class="layui-input-block">
						<textarea type="text" name="desc" placeholder="请输入" autocomplete="off" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">概览</label>
					<div class="layui-input-block">
						<!--<textarea type="text" name="overview" placeholder="请输入" autocomplete="off" class="layui-input" style="height: auto"></textarea>-->
						<div id="editor" name="overview"></div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">课程发布</label>
					<div class="layui-input-inline">
						<select name="delFlag" lay-filter="delFlag" id="delFlag" lay-verify="required">
							<option value="">--请选择--</option>
							<option value="2">暂不发布</option>
							<option value="0">申请发布</option>
						</select>
						<!--<input type="hidden" id="menu" name="delFlag" placeholder="请选择" autocomplete="off" class="layui-input">-->
						<!--<input type="checkbox" id="kcfb" name="" lay-skin="switch" lay-text="开启|关闭" lay-filter="fabu" checked>-->
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">课程公开</label>
					<div class="layui-input-inline" style="width: auto">
						<input type="checkbox" id="hasPublic" name="hasPublic" lay-skin="switch" lay-text="是|否" lay-filter="hasPublic">
					</div>
					<span class="public-prompt">若公开,课程将进入公开课程库,任何教师用户均有权限使用</span>
				</div>
				<!--<input type="hidden" name="pic" class="layui-input" id="picPath">-->
				<input type="hidden" name="id" value="">
				<button lay-filter="edit" lay-submit style="display: none;"></button>
				<div class="layui-form-item">
					<label class="layui-form-label">课程图片</label>
					<div class="layui-input-inline">
						<input type="text" placeholder="图片Url" name="pic" class="layui-input" id="picPath">
					</div>
					<span class="public-prompt">若图片为线上图片,可直接填入图片链接,若为本地图片,请点击"本地上传"</span>
				</div>
				<div class="layui-input-block">
					<div class="layui-upload">
						<button type="button" class="layui-btn layui-btn-sm" id="upload">上传图片</button><span id="demoText" style="color: #b66; margin-left:20px;"></span>
						<div class="layui-upload-list">
							<img class="layui-upload-img" id="demo1">
						</div>
					</div>
				</div>
			</form>

		</div>
	</div>
</div>
<script src="../js/jquery-1.10.0.js"></script>
<script src="../js/template-native.js"></script>
<!--<script src="../js/Global.js"></script>-->
<script>
	$(document).ready(function(){
//		alert(JSON.parse(getCookie('user')).token)
		var form = layui.form();

		if(JSON.parse(getCookie('user')).roleType == "2"){
			$("#delFlag option").last().text("发布").attr("value","1");
			form.render();
		}

		var data={
			dict:{
				type:'course_tag'
			}
		};
		var url=HOST+"system.dict.get.hsr";
		$.ajax({
			url: url,
			type: 'POST',
			headers: {
				token: JSON.parse(getCookie('user')).token
			},
			data: JSON.stringify(data),
			dataType: "json",
			success: function(result){
				for (var i= 0;i < result.value.length;i++){
                    if ($('#dict').attr('select-data') == result.value[i].value) {
                        $("#dict").append("<option value='"+result.value[i].value+"' selected>"+result.value[i].label+"</option>");
					} else {
                        $("#dict").append("<option value='"+result.value[i].value+"'>"+result.value[i].label+"</option>");
					}
				}
				form.render('select');
			},
			error:function(xhr){
				alert("错误提示： " + xhr.status + " " + xhr.statusText);
			}
		});

        form.on('select(fenlei)', function(data){
            $("#dict").attr('select-data',data.value);
        });

	});

    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload'
            ,url: '/servlet/fileUploadServlet?token='+JSON.parse(getCookie('user')).token
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
                layer.load(); //上传loading
            }
            ,done: function(res){
                var demoText = $('#demoText');
                if(res.code === 0){
                    demoText.html('<span style="color: #b66;">上传成功</span>');
                    $('#picPath').val(res.value[0].url);
                }
                layer.closeAll('loading'); //关闭loading
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #b66;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
                layer.closeAll('loading'); //关闭loading
            }
        });
    });
</script>
<!-- 注意， 只需要引用 JS，无需引用任何 CSS ！！！-->
<script type="text/javascript" src="js/wangEditor.min.js"></script>
<script type="text/javascript">
    var E = window.wangEditor;
    var editor = new E('#editor');
    // 或者 var editor = new E( document.getElementById('#editor') )
    editor.customConfig.uploadImgServer = '/servlet/richtextImgUploadServlet?token='+JSON.parse(getCookie('user')).token;
    editor.create()
</script>